package com.qezhhnjy.bilibili.controller;

import com.qezhhnjy.bilibili.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhaoyangfu - 2021/4/3 15:24
 */
@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String port;

    @GetMapping("/hystrix/ok/{id}")
    public String paymentInfoOK(@PathVariable("id") int id) {
        return paymentService.paymentInfoOK(id);
    }

    @GetMapping("/hystrix/timeout/{id}")
    public String paymentInfoTimeout(@PathVariable("id") int id) throws Exception {
        return paymentService.paymentInfoTimeout(id);
    }

    // 服务熔断
    @GetMapping("/hystrix/circuit/{id}")
    public String paymentInfoCircuit(@PathVariable("id") int id) {
        return paymentService.paymentCircuitBreaker(id);
    }
}
